//重载运算符
use std::ops::Add;
#[derive(Debug,PartialEq)]
pub(crate) struct Point {
    pub(crate) x: i32,
    pub(crate) y: i32,
}
//pub trait Add<Rhs = Self> 默认泛型类型为当前类型。
impl Add for Point {
    type Output = Point;
    fn add(self, other: Point) -> Point {
        Point {
            x: self.x + other.x,
            y: self.y + other.y,
        }
    }
}

#[derive(Debug)]
pub struct Millimeters(pub u32);
pub struct Meters(pub u32);
//泛型+关联类型demo
//为Millimeters实现Add<Meters> trait。
impl Add<Meters> for Millimeters {
    type Output = Millimeters;
    //直接编织为Millimeters的方法。
    fn add(self, other: Meters) -> Millimeters {
        Millimeters(self.0 + (other.0 * 1000))
    }
}